<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../include/taglib.jsp" %>

<!-- Modal -->
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" id="editPage">
        </div>
    </div>
</div>
<div class="row">
    <div class="col-md-12">
        <div class="form-panel">
            <h4 class="mb"><a href="javascript:jumpMenu('${ctx}/index/usual')"> 运营平台 </a><i class="fa fa-angle-right"></i>
                <c:forEach items="${products}" var="product">
                    <c:if test="${enabledPro == product.proNum}">
                        <a href="javascript:jumpMenu('${ctx}/rank/page?enabledPro=${product.proNum}')">${product.name}(排行榜)管理</a>
                    </c:if>
                </c:forEach>
            </h4>
            <form class="form-inline" role="form" id="sourceForm" method="post">
                <input type="hidden" name="enabledPro" value="${enabledPro}"/>
                <div class="form-group">
                    <label class="sr-only"></label>
                    <input id="name" type="text" class="form-control" name="colName" placeholder="名称"
                           value="${colName}">
                </div>
                <div class="form-group">
                    <label class="control-label">过滤 (启用状态) :</label>
                    <input type="checkbox" value="1" name="colState" style="zoom: 150%"
                           onclick="$('#searchSubmit').click();">
                </div>
                <div class="pull-right">
                    <button type="button" class="btn btn-theme03"
                            onclick="document.getElementById('sourceForm').reset();$('#searchSubmit').click();">清 除
                    </button>
                    <button type="button" class="btn btn-theme" id="searchSubmit"
                            onclick="queryList('${ctx}/rank/list', 'sourceForm', '_list')">搜 索
                    </button>
                    <button type="button" class="btn btn-theme04" id="addBtn" data-toggle="modal" data-target="#myModal"
                            onclick="edit();">增 加
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<%--<div class="row mt">
    <div class="col-md-12">
        <div class="form-panel">
        </div>
    </div>
</div>--%>
<div class="row">
    <div class="col-md-12">
        <div class="pull-right">
            <button class="btn btn-theme" id="saveSort"
                    style="width:150px;margin-right: 30px;">
                保 存 排 序
            </button>
        </div>
        <div class="content-panel" id="_list">
        </div><!-- /content-panel -->
    </div><!-- /col-md-12 -->
</div>
<script type="text/javascript">
    $(function () {
        $("#searchSubmit").click();
        $("#sourceForm input").keydown(function (e) {
            if (e.which == 13) {//.which属性判断按下的是哪个键，回车键的键位序号为13
                $("#searchSubmit").click();//触发搜索按钮的点击事件
                return false;
            }
        });
    });
    $("#saveSort").bind("click", function () {
        var $idList = $('input[name="sortIds"]');
        if ($idList.length > 1) {
            var jdata = $idList.serializeArray();
            var pageSizeNo = $("#_list").find("input[name='pageSizeNo']").val();
            var pageNo = $("#_list").find("input[name='pageNo']").val();
            jdata.push({
                name: "pageSizeNo",
                value: pageSizeNo
            });
            jdata.push({
                name: "pageNo",
                value: pageNo
            });
            var package = new AJAXPacket("${ctx}/rank/saveSort");
            package.data.data = jdata;
            core.ajax.sendPacket(package, function (response) {
                if (response.data.success) {
                    alertMsg.correct("成功！");
                    jumpPageTo('_list');
                } else {
                    alertMsg.error(response.data.errMsg);
                }
            });
        }
    });

    function edit(id) {
        var package = new AJAXPacket("${ctx}/rank/editPage");
        package.data.data.id = id;
        core.ajax.dynamicLoadpage(package, "editPage");
        package = null;
    }

    function del(id) {
        var del = function () {
            var package = new AJAXPacket("${ctx}/rank/del");
            package.data.add("id", id);
            core.ajax.sendPacket(package, function (response) {
                if (response.data.success) {
                    alertMsg.correct("成功！");
                    jumpPageTo('_list');
                } else {
                    alertMsg.error(response.data.errMsg);
                }
            });
            package = null;
        }
        alertMsg.confirm('确定执行此删除操作吗？', del);
    }
</script>